package smecta.client.print.service.file;

import lombok.extern.slf4j.Slf4j;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.document.DefaultDocumentFormatRegistry;
import org.jodconverter.core.office.OfficeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
@Slf4j
@Component
public class FileTypeConvertService {

    @Autowired(required=false)
    private DocumentConverter documentConverter;

    public void convertToPDF(String inputFilePath, String outputFilePath) {
        try {
            documentConverter.convert(new File(inputFilePath)).to(new File(outputFilePath)).as(DefaultDocumentFormatRegistry.PDF).execute();
        } catch (OfficeException e) {
            log.error("convertToPDF error:{}", e);
        }
    }
}
